package com.app.newiptv.bean;

import android.os.Parcel;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by jiaxing
 */
public class Program extends Content {
    public String date = "1970.01.01";
    public String startTimeDate;
    public String endTimeDate;
    public long endTime;
    public long startTime;
    public long duration;
    public Program() {
        super();
    }

    public boolean isTVOD() {
        return System.currentTimeMillis() > startTime + duration;
    }

    public long getCurrentPosition() {
        long currentTime = System.currentTimeMillis();
        return Math.min(currentTime - startTime, duration);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(parentID);
        dest.writeString(contentID);
        dest.writeString(name);
        dest.writeParcelable(imgSource, flags);
        dest.writeString(type);
        dest.writeMap(extras);
        dest.writeString(date);
        dest.writeString(startTimeDate);
        dest.writeString(endTimeDate);
        dest.writeLong(startTime);
        dest.writeLong(duration);

    }

    public static final Creator<Program> CREATOR = new Creator<Program>() {
        @Override
        public Program createFromParcel(Parcel source) {
            String parentID = source.readString();
            String contentID = source.readString();
            String name = source.readString();
            ImageSource imgSource = source.readParcelable(ImageSource.class.getClassLoader());
            String type = source.readString();
            Map extras = source.readHashMap(HashMap.class.getClassLoader());
            String date = source.readString();
            String startTimeDate = source.readString();
            String endTimeDatete = source.readString();
            long startTime = source.readLong();
            long duration = source.readLong();
            Program program = new Program();
            program.parentID = parentID;
            program.contentID = contentID;
            program.name = name;
            program.imgSource = imgSource;
            program.type = type;
            program.extras = extras;
            program.date = date;
            program.startTimeDate = startTimeDate;
            program.endTimeDate = endTimeDatete;
            program.startTime = startTime;
            program.duration = duration;
            return program;
        }

        @Override
        public Program[] newArray(int size) {
            return new Program[size];
        }
    };
}
